﻿using Microsoft.Extensions.Localization;
using PHMEE.Localization;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;

namespace PHMEE
{
    public class BaseinfoDataSeed : IDataSeedContributor, ITransientDependency
    {
        private readonly IGuidGenerator guidGenerator;
        private readonly IStringLocalizer<PHMEEResource> L;
        private readonly ICompanyRepository companyRepository;
        private readonly ICompanyManager companyManager;
        private readonly IFleetRepository fleetRepository;
        private readonly IFleetManager fleetManager;
        private readonly IVesselRepository vesselRepository;
        private readonly IVesselManager vesselManager;
        private readonly IMainenanceAdviceRepository mainenanceAdviceRepository;
        private readonly IMainenanceAdviceManager mainenanceAdviceManager;
        private readonly IBearFactoryRepository bearFactoryRepository;
        private readonly IBearLibRepository bearLibRepository;

        public BaseinfoDataSeed(IGuidGenerator guidGenerator, IStringLocalizer<PHMEEResource> L, ICompanyRepository companyRepository, ICompanyManager companyManager, IFleetRepository fleetRepository, IFleetManager fleetManager, IVesselRepository vesselRepository, IVesselManager vesselManager, IMainenanceAdviceRepository mainenanceAdviceRepository, IMainenanceAdviceManager mainenanceAdviceManager, IBearFactoryRepository bearFactoryRepository, IBearLibRepository bearLibRepository)
        {
            this.guidGenerator = guidGenerator;
            this.L = L;
            this.companyRepository = companyRepository;
            this.companyManager = companyManager;
            this.fleetRepository = fleetRepository;
            this.fleetManager = fleetManager;
            this.vesselRepository = vesselRepository;
            this.vesselManager = vesselManager;
            this.mainenanceAdviceRepository = mainenanceAdviceRepository;
            this.mainenanceAdviceManager = mainenanceAdviceManager;
            this.bearFactoryRepository = bearFactoryRepository;
            this.bearLibRepository = bearLibRepository;
        }

        public async Task SeedAsync(DataSeedContext context)
        {
            await SeedBearAsync();
        }

        private async Task SeedBearAsync()
        {
            List<BearFactory> bearFactories = new List<BearFactory>()
            {
                new ("barden"),
                new ("Cooper"),
                new ("fafnir"),
                new ("fag/stamford"),
                new ("link belt"),
                new ("messinger"),
                new ("mrc"),
                new ("NDH"),
                new ("nsk"),
                new ("10"),
                new ("seal"),
                new ("skf"),
                new ("timken tapered rollers"),
                new ("Torrington"),
                new ("user"),
                new ("16"),
                new ("BCA"),
                new ("BOW"),
                new ("19"),
                new ("DGE"),
                new ("21"),
                new ("22"),
                new ("INA"),
                new ("KAY"),
                new ("KBC"),
                new ("KOY"),
                new ("LBT"),
                new ("McG"),
                new ("29"),
                new ("MHP"),
                new ("31"),
                new ("NIC"),
                new ("33"),
                new ("NTN"),
                new ("REX"),
                new ("RHP"),
                new ("ROL"),
                new ("ROT"),
                new ("39"),
                new ("40"),
                new ("SNR"),
                new ("STR"),
                new ("TMK"),
                new ("UserDefined"),
                new ("Kaydon"),
                new ("XXX"),
                new ("JAP"),
                new ("ND5"),
                new ("STE"),
                new ("Bower"),
                new ("RAM"),
                new ("Gamet"),
                new ("Browning")
            };
            var entities = await bearFactoryRepository.PhmeeGetAll();
            var names = entities.Select(e => e.Name).ToList();
            bearFactories = bearFactories.Where(item => !names.Contains(item.Name)).ToList();

            await bearFactoryRepository.PhmeeCreateMany(bearFactories);
        }
    }
}
